<?php #//AJAX PHP PENNY AUCTION v.1.1

#///////////////////////////////////////////////////////////
#//  COPYRIGHT 2009 Aaron Helmlinger ALL RIGHTS RESERVED  //
#///////////////////////////////////////////////////////////
include "./includes/config.inc.php";


$TIME = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d"),date("Y"));
$NOW = date("YmdHis",$TIME);


$auction_id = $_POST['id'];  
$id2 = $_SESSION["PHPAUCTION_LOGGED_IN"];


       
      $query_title1 = "select title, current_bid, shipping_fee, retail, bid_credits_reqd from PHPAUCTIONXL_auctions where id=$auction_id";
                             $query_title2 =  mysql_query ($query_title1);
                                $item_name = mysql_result($query_title2,0,"title");
                               $price = mysql_result($query_title2,0,"current_bid");
                              $shipping_fee = mysql_result($query_title2,0,"shipping_fee");
                              $retail = mysql_result($query_title2,0,"retail");
                              $bid_credits_reqd = mysql_result($query_title2,0,"bid_credits_reqd");


           $query_title1 = "select email from PHPAUCTIONXL_users where id=1";
                             $query_title2 =  mysql_query ($query_title1);
                                $paypal_email = mysql_result($query_title2,0,"email");
                                
            $query33 = mysql_fetch_array(mysql_query("SELECT tax_rate_percentage,average_bid_price FROM PHPAUCTIONXL_version_1_3 WHERE id=1"));
                                   $tax_rate_percentage1 = $query33['tax_rate_percentage'];
                                  $average_bid_price2 = $query33['average_bid_price'];
        
                                             $query_settings = "select * from PHPAUCTIONXL_version_2_1 where id='1'";
                             $query_settings2 =  mysql_query ($query_settings);
                                $nat_tax_rate2 = mysql_result($query_settings2,0,"nat_tax_rate");                             
                                 $tax_state2 = mysql_result($query_settings2,0,"tax_state"); 
                                   
                                   
                                    $query_settings = "select * from PHPAUCTIONXL_users where id=$id2";
                             $query_settings2 =  mysql_query ($query_settings);
                                $users_state = mysql_result($query_settings2,0,"prov");     
        
        if($id2) {
  
             
    
      $query = "select * from PHPAUCTIONXL_bids2 WHERE bidder='$id2' AND auction='$auction_id'";
$result = mysql_query($query);
if($result) {
$number_of_bids = mysql_num_rows($result);
   }
   
if(empty($result)) {
$number_of_bids = 0;
   }   
              $bid_expenses = $average_bid_price2 * $bid_credits_reqd * $number_of_bids;
           $price2 = $retail - $bid_expenses + $shipping_fee; 
           $taxes = $price2 * $tax_rate_percentage1;
     
                  if( $tax_state2 == $users_state ) {   
  if (!empty($tax_rate2)) {     
$taxprice1 = $price2 * $tax_rate_percentage1;
$price = round(($price2 + $taxprice1),2);
if (!empty($nat_tax_rate2)) { 
$taxprice2 = ( $price2 * $tax_rate_percentage1 ) * $nat_tax_rate2;
$price = round(($price2 + $taxprice2),2);
}}  
  
      if (empty($tax_rate2)) {     
$taxprice1 = 0;
$price = round(($price2),2);
if ( empty($nat_tax_rate2)) {
$taxprice2 = 0;
$price = round(($price2),2); 
}}  
  }        

 
           
           
            
            
         
            
            
            
            
            
   $query = "select * from PHPAUCTIONXL_payments WHERE userid='$id2' AND itemid='$auction_id' AND itemtype='BuyNow-Item-ID'";
$result = mysql_query($query);
if($result) {
$number_of_bids = mysql_num_rows($result);
   }
                   
                   
                              
   if(empty($number_of_bids)) {
  $item_number = "User-Id:";
  $item_number .=     $id2;
  $item_number .=     ":BuyNow-Item-ID:";
  $item_number .=     $auction_id;
  $item_number .=     ":Price:";
  $item_number .=     $price; 
  
   



include "header.php";
include phpa_include("template_buynow_paypal_php.html");
include "footer.php";
   }
   
      if($number_of_bids) {
  include "header.php"; ?> 
       <? 
       
  $tabid = 2; // Change This Number To Correspond To The Tab You Want Activated
  include "tab_menu.php"; // To Change The Tabs - Modify This File
  $subtabid = "my auctions"; // Change This Variable To Correspond To Tab Sub Menu You Want To Display
  include "tab_submenu.php"; //To Change The Sub Menu - Modify This File
  include "category_menu.php"; //To Change The Category Menu - Modify This File
  $page_title_text = $BUY_NOW_PAYMENT; //Change This Text To The Text That You Want To Show In The Page Title Bar
  $page_title_note = ""; //Change This Text To Display A Note In The Page Title Bar Area
  include "page_title.php"; //To Change The Page Title Look - Modify This File
  ?>            
      
     <? print $tab_menu ?>  <!-- This displays the Tab Menu - Delete It, If You Do Not Want It Show On The Screen  -->
     <? print $tab_submenu ?>  <!-- This displays the Tab Sub Menu - Delete It, If You Do Not Want It Show On The Screen    -->
     <? print $category_menu ?>  <!--  This displays the Category  Menu - Delete It, If You Do Not Want It Show On The Screen  -->
     <? print $page_title_content_box_start; ?>  <!-- This displays the Title Bar And Content Border - Delete It, If You Do Not Want It Show On The Screen  -->
                                                 <!-- You will also need to delete the "$page_title_content_box_stop" below  -->
    <?      
  echo "
  <BR><BR>
  <CENTER><h1>$MSG_BUYNOW_ALREADY_PURCHASED</h1></CENTER>
  <BR><BR>
      ";
        print $page_title_content_box_stop; 
include "footer.php"; 
   
   
     }
      } 
?>

       